package com.seed.web.struts.sysmanager;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.seed.commons.dbquery.PageViewForSQL;
import com.seed.service.sysmanager.IDepartment;
import com.seed.web.core.BaseActionSupport;
import com.seed.web.form.sysmanager.DepartmentForm;

@Controller
@Scope("prototype")
public class DepartmentAction extends BaseActionSupport {

	private static final long serialVersionUID = 1L;

	private DepartmentForm dept;

	public DepartmentForm getDept() {
		return dept;
	}

	public void setDept(DepartmentForm dept) {
		this.dept = dept;
	}

	@Resource(name = "pageViewForSQL")
	private PageViewForSQL pv;

	public PageViewForSQL getPv() {
		return pv;
	}

	public void setPv(PageViewForSQL pv) {
		this.pv = pv;
	}

	@Resource
	private IDepartment deptService;

	public String saveDept() throws Exception {
		boolean flag = this.deptService.saveDept(dept);
		if (flag) {
			saveMessage("部门添加成功！");
		} else {
			saveMessage("部门添加 失败！");
		}
		return "msg";
	}

	public String findDeptAll() throws Exception {

		this.getBaseform().getRequest().setAttribute("dept", this.deptService.queryDept());

		if ("addemp".equals(this.getBaseform().getType())) {
			return "addemp";
		} else {
			return "finddeptall";
		}
	}

	public String findDept() throws Exception {
		pv.setPageModel(this.deptService.getScrollData(pv.getFirstResult(),
				pv.getLineSize()));
		this.getBaseform().getRequest().setAttribute("scrolldata", pv);
		return "finddept";
	}
}
